package com.hsc.www;

import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

@CacheConfig(cacheNames = "users")
public interface UserServices {

    @Cacheable( key ="#root.targetClass+':'+#root.target+':' + #root.methodName +':'+ #id")
    User findById(int id);

    @Cacheable()
    User findByIdAndName(int id,String name);

    @Cacheable()
    User findByName(String name);

    @Cacheable()
//    List<User> findAll();

    @CacheEvict(allEntries=true)
    int addUser(Integer id,String name);

    @CacheEvict(allEntries=true)
    void updateById(int id,String name);

    //如果指定为 true，则方法调用后将立即清空所有缓存
    @CacheEvict(allEntries=true)

    void deleteById(int id);
    @Cacheable()
     List<User> findAll();
}